package io.xccit.controller;

import io.xccit.dao.EmployeeDao;
import io.xccit.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Collection;

/**
 * @author CH_ywx
 * @Date 2023-04-02
 * @Description 员工控制层
 */
@Controller
public class EmployeeController {
    @Autowired
    private EmployeeDao employeeDao;
    @RequestMapping(value = "/employee",method = RequestMethod.GET)
    public String getAllEmployee(Model model){
        Collection<Employee> employeeList = employeeDao.getAllEmployees();
        model.addAttribute("employeeList",employeeList);
        return "employee_list";
    }
    @RequestMapping(value = "/employee",method = RequestMethod.POST)
    public String saveEmployee(Employee employee,Model model){
        employeeDao.saveEmployee(employee);
        model.addAttribute("result","SUCCESS!");
        //重定向到/employee---->GET
        return "redirect:/employee";
    }
}
